<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
		<link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
		<title>区块链推广管理中心</title>
	</head>
	<style>
		body{
			background: #ffffff;
		}
		.main{
			width: 80%;
			margin: 0 auto;
		}
		.main>.title{
			text-align: center;
			margin-top: 5%;
		}
		#template{
			display: none;
		}
		.left_frame,
		.right_frame {
			width: 50%;
			display: inline-block;
			float: left;
		}
		
		.right_frame {
			width: 45%;
			float: right;
		}
		
		.block {
			font-size: 25px;
			line-height: 60px;
			height: 60px;
		}
		
		.block:hover {
			background: #f5f5f5;
		}
		
		.block>.ctrl {
			text-align: right;
			display: inline-block;
			float: right;
			height: 100%;
		}
		
		.block .weui_switch {
			vertical-align: middle;
		}
		
		.weui_cells_title {
			font-size: 20px;
		}
	</style>

	<body>
		<div class='main' style="position: relative;">
			<a href="/telegram.html" style="position: absolute; top: -10px;"><img src="http://cmanage.shinechain.io/imgs/return.jpg" height="48" width="48" style="vertical-align:middle;" /></a>
			<h2 class='title'>自动删除信息</h2>
	<p style="font-size:large;color: #888888;margin-left: 20px;">&thinsp; &thinsp; &thinsp; &thinsp; &thinsp; 每分钟自动更新管理员名单</p>
	<div class='left_frame'>
		<div id='template' class='block'>
			{{index}}、{{name}}
			<div class='ctrl'>
				<input class="weui_switch" type="checkbox" {{checked}} data-slug='{{slug}}'>
			</div>
		</div>
	</div>
	<div class='right_frame'>
		<div class="weui_cells_title">关键词白名单</div>
		<div class="weui_cells weui_cells_form">
			<div class="weui_cell">
				<div class="weui_cell_bd weui_cell_primary">
					<textarea id='whiteList' class="weui_textarea" placeholder="请输入文本，每个关键词分行填写" rows="3"></textarea>
					<div class="weui_textarea_counter"><span class="count">0</span>/<span class="count_max">5000</span></div>
				</div>
			</div>
		</div>
		<div class="weui_btn_area">
			<a id="whiteListSubmit" href="javascript:" class="weui_btn weui_btn_primary">提交</a>
		</div>
		<div class="weui_cells_title">关键词黑名单</div>
		<div class="weui_cells weui_cells_form">
			<div class="weui_cell">
				<div class="weui_cell_bd weui_cell_primary">
					<textarea id='blackList'  class="weui_textarea" placeholder="请输入文本，每个关键词分行填写" rows="3"></textarea>
					<div class="weui_textarea_counter"><span class="count">0</span>/<span class="count_max">5000</span></div>
				</div>
			</div>
		</div>
		<div class="weui_btn_area">
			<a id="blackListSubmit" href="javascript:" class="weui_btn weui_btn_primary">提交</a>
		</div>
	</div>
</div>

		<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
$(function(){
	var options = [{
		'name':'删除非管理员的图片',
		'checked': '',
		'slug': 'deletePhoto'
		},{
		'name':'删除非管理员的文件',
		'checked': '',
		'slug': 'deleteFile'
		},{
		'name':'删除非管理员发的视频信息',
		'checked': '',
		'slug': 'deleteVideo'
		},{
		'name':'删除非管理员发的语音',
		'checked': '',
		'slug': 'deleteVoice'
		},{
		'name':'删除非管理员转发的信息',
		'checked': '',
		'slug': 'deleteForward'
		},{
		'name':'删除非管理员含有链接的信息',
		'checked': '',
		'slug': 'deleteSendLink'
		},{
		'name':'删除一分钟内连续3次相同信息（刷屏）',
		'checked': '',
		'slug': 'disableSpam'
		},{
		'name':'删除出入群信息',
		'checked': '',
		'slug': 'deleteJoinOutMsg'
		},{
		'name':'删除信息的时候检查白名单，若是白名单则不处理',
		'checked': '',
		'slug': 'useWhiteList'
		},{
		'name':'删除黑名单关键字的信息',
		'checked': '',
		'slug': 'deleteAdKeyFlag'
		}
	];
	var ip = 'http://bot.shinechain.io';

				var clickThing = function (){
					$('.weui_switch').click(function() {
							var slug = $(this).data('slug');
							var checked = $(this).is(":checked");
							var self = $(this);
							$.get(ip+'/botApi/botMethod?botMethod='+slug, function(result){
								if (result && result.status == 200){
									if(result.botMethod == true){
									self.prop("checked",true); 
									}else{
									self.prop("checked",false); 
									}	
									setButton();
								}else {
									window.alert(result.errorMsg);
								}
							});
						});
				}
				var setButton = function() {
					$('.block').each(function() {
						if(!$(this).find('.title input').is(":checked")) {
							$(this).find('.body a').hide();
							$(this).find('.body p').show();
						} else {
							$(this).find('.body a').show();
							$(this).find('.body p').hide();
						}
						if($(this).find('.body a').attr('href') == '') {
							$(this).find('.body a').hide();
							$(this).find('.body p').show();
						}
					})
				}
				var getInfo = function () {
					$.get(ip + '/botApi/getAll', function(res) {
					$('#blackList').text(res.blackKeylist);
						$('#whiteList').text(res.whiteKeyList);
						
						options.map(function(value, index) {
							var slug = value.slug;
							if(res.botMethod[slug] == true) {
								options[index]['checked'] = 'checked';
							}
						});
						options.map(function(value, index){
							var html = $('#template').clone().attr('id', '').prop("outerHTML");
							html = html.replace("{{index}}", index + 1);
							for(var index in value){
								html = html.replace("{{"+index+"}}", value[index]);
							}
							$('.left_frame').append(html)
						});
						setButton();
						clickThing();
					});
				}
				getInfo();
	
	$('textarea').on('input', function(){
		var max =  $(this).parent().find('.count_max').text();
		var text = $(this).val();
		var len = text.length;
		$(this).parent().find('.count').text(len);    
		if(len > max){
			$(this).closest('.weui_cell').addClass('weui_cell_warn');
		} else {
			$(this).closest('.weui_cell').removeClass('weui_cell_warn');
		}
	});
  
	//白名单
	$('#whiteListSubmit').click(function(){
	var whiteList = $('#whiteList').val();
	var self = $('#whiteList');
	jsonArr = {'whiteKey' : whiteList};
		$.ajax({
                    url: ip + '/botApi/setWhiteKey',
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    data: JSON.stringify(jsonArr),
                    success: function(res) {
                        self.text(res.whiteKeyList);
                        alert('提交成功');
                    },
        });
	});
	//黑名单
	$('#blackListSubmit').click(function(){
	var blackList = $('#blackList').val();
	var self = $('#blackList');
	jsonArr = {'blackKey' : blackList};
		$.ajax({
                    url: ip + '/botApi/setBlackKey',
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    dataType: 'json',
                    data: JSON.stringify(jsonArr),
                    success: function(res) {
                        self.text(res.blackKeyList);
                        alert('提交成功');
                    },
        });
	});
});
</script>
</body>
</html>